home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / recom11.zip / RECOM.BAS < prev    next >
BASIC Source File  |  1997-07-01  |  6KB  |  185 lines

  1. 'ReCom 1.1: Utility to recomment source files
  2. 'March 4, 1997, July 1, 1997 by Tika Carr (some code by Joe Negron)
  3. '
  4. 'No warranties or guarantees are expressed or implied. Free for your own
  5. 'use & modification, just give the author(s) proper credit.
  6. '
  7. 'NOTES: This Source will work only in QuickBasic 4.5.
  8. '       Start with QB /L QB.QLB
  9. '
  10. 'See RECOM.DOC for more information
  11.  
  12. DEFINT A-Z
  13.  
  14. '$INCLUDE: 'qb.bi'
  15.  
  16. DECLARE FUNCTION Exist% (FileName$)
  17. DECLARE SUB Help ()
  18.  
  19. DIM arg$(1 TO 85)
  20.  
  21. 'Program ID
  22. PRINT
  23. PRINT "ReCom 1.1: Utility to recomment your source files"
  24. PRINT "March 4, 1997, July 1, 1997 by Tika Carr (some code by Joe Negron)"
  25. PRINT
  26.  
  27. 'Get Paramters:
  28.  
  29. IF COMMAND$ <> "" THEN
  30.     I = 1: j = 1
  31.     DO UNTIL I >= LEN(COMMAND$)
  32.         WHILE MID$(COMMAND$, I, 1) <> " " AND MID$(COMMAND$, I, 1) <> ""
  33.             arg$(j) = arg$(j) + MID$(COMMAND$, I, 1)
  34.             I = I + 1
  35.         WEND
  36.         I = I + 1: j = j + 1
  37.     LOOP
  38. END IF
  39.  
  40. 'Check Paramters
  41. IF arg$(1) = "" THEN Help       ' No paramters found
  42. IF INSTR("/-", LEFT$(arg$(1), 1)) = 0 THEN
  43.     Help  'First parameter a switch?
  44. ELSE    'Parse Parameter
  45.     Lang$ = MID$(arg$(1), 2, 1)
  46.     Source$ = RIGHT$(arg$(1), 1)
  47.     IF Lang$ = Source$ AND LEN(arg$(1)) > 2 THEN Help   ' Bad format
  48.     IF INSTR("QCPA", Lang$) = 0 THEN Source$ = "" 'One-letter switch
  49. END IF
  50.  
  51. 'Check Filename
  52. IF Exist(arg$(2)) >= 0 THEN PRINT arg$(2); " not found.": Help
  53.  
  54. 'All tests pass. Figure new filename based on Lang$ and arg$(2)
  55.  
  56. 'Check for a "." and if there, chop off extension
  57. I = INSTR(arg$(2), ".")
  58. IF I THEN
  59.     OutFile$ = LEFT$(arg$(2), I)
  60. ELSE
  61.     OutFile$ = arg$(2) + "."
  62. END IF
  63. 'Check filename size (8-char filename plus ".")
  64. IF LEN(OutFile$) > 9 THEN Help
  65.  
  66. 'Check Lang$ and add extension, and set up comment string
  67.  
  68. 'QBasic/QuickBasic 4.5/GWBASIC
  69. IF INSTR("QGCPABIS", Lang$) = 0 THEN Help     ' Wrong Language Parameter
  70. IF INSTR("QG", Lang$) THEN
  71.     ' No Header/Source Specified
  72.     IF Lang$ = "Q" AND INSTR("SH", Source$) = 0 OR LEN(Source$) = 0 AND Lang$ <> "G" THEN Help
  73.     IF Source$ = "H" THEN OutFile$ = OutFile$ + "BI" ELSE OutFile$ = OutFile$ + "BAS"
  74. END IF
  75. IF Lang$ = "Q" THEN
  76.     Comment$ = "'"
  77. ELSEIF Lang$ = "G" THEN Comment$ = "REM"
  78. END IF
  79.  
  80. 'C/C++ Header/Source
  81. 'Note that a * is used for ANSI C and will be fixed as needed for /**/ later.
  82. IF INSTR("CP", Lang$) THEN
  83.     ' No Header/Source specified
  84.     IF INSTR("SH", Source$) = 0 OR LEN(Source$) = 0 THEN Help
  85.     IF Source$ = "H" THEN
  86.         IF Lang$ = "P" THEN Comment$ = "//" ELSE Comment$ = "*"
  87.         OutFile$ = OutFile$ + "H"
  88.     ELSE
  89.         IF Lang$ = "C" THEN
  90.             OutFile$ = OutFile$ + "C": Comment$ = "*"
  91.         ELSE OutFile$ = OutFile$ + "CPP": Comment$ = "//"
  92.         END IF
  93.     END IF
  94. END IF
  95.  
  96. 'Assembly Language
  97. IF Lang$ = "A" THEN
  98.     ' No Header/Source specified
  99.     IF INSTR("SH", Source$) = 0 OR LEN(Source$) = 0 THEN Help
  100.     Comment$ = "#"
  101.     IF Source$ = "H" THEN
  102.         OutFile$ = OutFile$ + "INC"
  103.     ELSE OutFile$ = OutFile$ + "ASM"
  104.     END IF
  105. END IF
  106.  
  107. IF Lang$ = "B" THEN OutFile$ = OutFile$ + "BAT": Comment$ = "REM" 'BAT File
  108. IF Lang$ = "I" THEN OutFile$ = OutFile$ + "INI": Comment$ = ";"   'INI File
  109. IF Lang$ = "S" THEN OutFile$ = OutFile$ + "SYS": Comment$ = "REM" 'SYS File
  110.  
  111. 'Check to be sure input and output files are not the same
  112. IF arg$(2) = OutFile$ THEN
  113.     PRINT "*** ERROR ***"
  114.     PRINT "Switch used was: "; arg$(1)
  115.     PRINT "Input File to operate on is: "; arg$(2)
  116.     PRINT "File conversion was to be output to: "; OutFile$
  117.     PRINT "Cannot write to input file!": PRINT
  118.     Help
  119. END IF
  120.  
  121. 'All set, now open files
  122. OPEN arg$(2) FOR INPUT AS #1: OPEN OutFile$ FOR OUTPUT AS #2
  123.  
  124.     ' Parse sources and comment accordingly
  125.     I = 0: y = CSRLIN
  126.     WHILE NOT EOF(1)
  127.         LINE INPUT #1, a$
  128.         'Show line # being worked on:
  129.         LOCATE y, 1: PRINT STRING$(79, 32);
  130.         LOCATE y, 1: PRINT "Processing Line #"; I; : I = I + 1
  131.         ' Neater source listing, parses out blank lines/comments
  132.         IF LEN(a$) > 1 THEN
  133.             IF Lang$ = "C" THEN
  134.                 'If its to be a header file, then no commenting is needed.
  135.                 IF Source$ = "H" THEN PRINT #2, a$ ELSE PRINT #2, "/* " + a$ + " */"
  136.             ELSE PRINT #2, Comment$ + " " + a$
  137.             END IF
  138.         ELSE PRINT #2, ""
  139.         END IF
  140.     WEND
  141. CLOSE
  142. LOCATE y, 1: PRINT STRING$(79, 32): LOCATE y, 1: PRINT "Done."
  143.  
  144. '***********************************************************************
  145. '* FUNCTION Exist%
  146. '*
  147. '* PURPOSE
  148. '*    Uses DOS ISR 21H, Function 4EH (Find First Matching Directory
  149. '*    Entry) to determine the existence of FileName$.
  150. '***********************************************************************
  151. FUNCTION Exist% (FileName$) STATIC
  152.      DIM IRegsX AS RegTypeX, ORegsX AS RegTypeX
  153.  
  154.      IRegsX.ax = &H4E00
  155.      IRegsX.cx = &H3F                          'search for all files
  156.      FileName$ = FileName$ + CHR$(0)           'must end with null byte
  157.  
  158.      IRegsX.ds = VARSEG(FileName$)             'load DS:DX with
  159.      IRegsX.dx = SADD(FileName$)               '  address of FileName$
  160.  
  161.      INTERRUPTX &H21, IRegsX, ORegsX
  162.      Exist% = ORegsX.ax = 0                    'if ax contains a value,
  163.                                                                                          '  remove the null byte
  164.      FileName$ = LEFT$(FileName$, LEN(FileName$) - 1)
  165. END FUNCTION
  166.  
  167. SUB Help
  168. PRINT "USAGE: recom /switch infile.ext"
  169. PRINT
  170. PRINT "These switches determine the output file and filename:"
  171. PRINT "/qx  QBasic/QuickBasic 4.5"
  172. PRINT "/cx  ANSI C"
  173. PRINT "/px  C++"
  174. PRINT "/ax  Assembly Language"
  175. PRINT "/g   GWBASIC"
  176. PRINT "/b   Batch File (.BAT)"
  177. PRINT "/i   .INI File"
  178. PRINT "/s   .SYS File"
  179. PRINT
  180. PRINT "NOTE: x must be either an 's' (for source) or 'h' (for header)"
  181. PRINT
  182. END
  183. END SUB
  184.  
  185.